<template>
<div class="sysLogin-box">
  <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position="left" label-width="0px" class="login-container">
    <h3 class="title">西安市出租汽车企业在线业务管理系统</h3>
    <el-form-item prop="account">
      <el-input type="text" v-model="ruleForm2.account" auto-complete="off" placeholder="账号"></el-input>
    </el-form-item>
    <el-form-item prop="checkPass">
      <el-input type="password" v-model="ruleForm2.checkPass" auto-complete="on" placeholder="密码"></el-input>
    </el-form-item>
    <el-checkbox v-model="checked" checked class="remember">记住账号</el-checkbox>
    <el-form-item style="width:100%;">
      <el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit2" :loading="logining">登录</el-button>
      <!--<el-button @click.native.prevent="handleReset2">重置</el-button>-->
    </el-form-item>
  </el-form>
</div>

</template>

<script>
  import { LoginApi } from '@/ajax';
  export default {
    data() {
      return {
        logining: false,
        ruleForm2: {
          account: 'test',
          checkPass: 'test'
        },
        rules2: {
          account: [
            { required: true, message: '请输入账号', trigger: 'blur' },
            //{ validator: validaePass }
          ],
          checkPass: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            //{ validator: validaePass2 }
          ]
        },
        checked: true
      };
    },
    methods: {
      handleReset2() {
        this.$refs.ruleForm2.resetFields();
      },
      handleSubmit2(ev) {

        var _this = this;
        /**test */
            // sessionStorage.setItem('user', JSON.stringify({username:'test',name:'test'}));
            // _this.$router.push({ path: '/home' });
            // return;
        /**test end */
        _this.logining = true;
       _this.$refs.ruleForm2.validate((valid) => {

          if (valid) {
            
            //_this.$router.replace('/table');
            //NProgress.start();
            var loginParams = { username: this.ruleForm2.account, password: this.ruleForm2.checkPass };
            LoginApi.requestLogin(loginParams).then(result => {
              _this.logining = false;
              //NProgress.done();
              let { message, code, data } = result;
              if (code !== "10000") {
                _this.$message({
                  message: '登录失败：'+message,
                  type: 'error',
                  duration:1800,
                  onClose:function (){
                    _this.logining = false;
                  }
                });
              } else {
                _this.$message({
                  message: message,
                  type: 'success',
                  duration:'1000',
                  onClose:function (){
                    _this.logining = false;
                    sessionStorage.setItem('user', JSON.stringify(data));
                    if(_this.HistoryGoHome){
                      _this.$router.push({ path: '/home' });
                    }else{
                      _this.$router.go(-1)
                    }
                  }
                });
              }
            }).catch(err => {

              _this.$message({
                message: '登录接口异常，请稍后重试!',
                type: 'error',
                duration:1800,
                onClose:function(){
                   _this.logining = false;
                }
              });
            });
          } else {
            console.log('error submit!!');
            _this.logining = false;
            return false;
          }
        }); 
      }
    }
  }

</script>

<style lang="scss">
.sysLogin-box{
  position: absolute;
  left:0;top:0;width: 100%;height:100%;
  background: url(../assets/loginbg.jpg) no-repeat center;background-size: cover;
}
  .login-container {
    /*box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.06), 0 1px 0px 0 rgba(0, 0, 0, 0.02);*/
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
   // margin: 180px auto;
   position: absolute;
   left:50%;
   top:50%;
    transform: translate(-50%,-50%);
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #dfe8f6;
    box-shadow: 0 0 25px #dfe8f6;
    .title {
      margin: 0px auto 40px auto;
      text-align: center;
      color: #15428F;
    }
    .remember {
      margin: 0px 0px 35px 0px;
    }
  }
</style>
